const { ipcMain, Menu, MenuItem, BrowserWindow, webContents } = require('electron');
const contextMenu = require('electron-context-menu');

// webview 右键菜单
let window;
const menu = new Menu()
menu.append(new MenuItem({
    label: '开发者工具',
    click() {
        if (window.isDevToolsOpened()) {
            window.closeDevTools();
        } else {
            window.openDevTools();
        }
    },
}));
ipcMain.on('open-context-menu', function (e, id) {
    if (id) {
        window = webContents.fromId(id);
    } else {
        window = BrowserWindow.fromWebContents(e.sender);
    }
    menu.popup({ window: BrowserWindow.fromWebContents(e.sender) });
});

// window 右键菜单
contextMenu({
    showCopyImage: true,
    showCopyImageAddress: true,
    showInspectElement: true,
    showServices: true,
    showSearchWithGoogle: false,
    labels: {
        copy: '复制',
        cut: '剪切',
        paste: '粘贴',
        copyLink: '复制链接',
        copyImage: '复制图片',
        inspect: '开发者工具',
    },
});
